﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Forums.Domain.Values
{
	using Falcon.Core.Domain;
	using Falcon.Core.Domain.Values;
	using Falcon.Core.Extensions;
	using Falcon.Core.Validation;
	using Falcon.Forums.Validators;

	public class ForumPermissionCreate : ValueBase<ForumPermissionCreate>
	{
		/// <summary>
		/// Gets or sets the forum id.
		/// </summary>
		/// <value>The forum id.</value>
		public int ForumId
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the role.
		/// </summary>
		/// <value>The role.</value>
		public string Role
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the actions.
		/// </summary>
		/// <value>The actions.</value>
		public ForumPermissionValue[] Actions
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the posts actions.
		/// </summary>
		/// <value>The posts actions.</value>
		public ForumPermissionValue[] PostsActions
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the topics actions.
		/// </summary>
		/// <value>The topics actions.</value>
		public ForumPermissionValue[] TopicsActions
		{
			get;
			set;
		}

		public override Validator<ForumPermissionCreate> Rules()
		{
			var rules = base.Rules();

			rules.Add(x => x.Role)
				.NotEmpty(Resources.Errors.Required.Fmt(Resources.Titles.Role));

			rules.Add(x => x.Role)
				.Custom(new ForumPermissionRoleMustExistValidator(), Resources.Errors.UserRoleNotFound);

			return rules;
		}

		/// <summary>
		/// Validates this instance.
		/// </summary>
		public override void Validate()
		{
			this.Rules().Validate(this);
		}
	}
}